import { createRouter, createWebHistory } from "vue-router";
import Layout from '@/pages/layout/index.vue'
import Home from '@/pages/home/index.vue'
import ResetPwd from '@/pages/resetPwd.vue'
import caseRoute from './case'
import backstageRoute from './backstage'
import homeRoute from './home'
import {storeToRefs} from "pinia";
import {useUser} from "@/store/user";
import {ElMessage} from "element-plus";

let routes= [
    {
        path: '/',
        name: 'defaultLayout',
        component: Layout,
        children: [
            {
                path: '',
                name: 'home',
                component: Home
            },

            {
                path: 'intro',
                name: 'intro',
                component: () => import('@/pages/Intro.vue')
            },

            {
                path: 'team',
                name: 'team',
                component: () => import('@/pages/team/index.vue')
            },
            {
                path: 'team/detail',
                name: 'teamDetail',
                component: () => import('@/pages/team/detail.vue')
            }
        ]
    },
    {
        path: '/resetPwd',
        name: 'resetPwd',
        component: ResetPwd,
    },
    backstageRoute,
    homeRoute,
    caseRoute
    //{
        //配置404页面
        //path: '/:catchAll(.*)',
        //name: '404',
        //component: () => import(''),
    //}
]
// 路由
const router = createRouter({
    history: createWebHistory(),
    routes
})
router.beforeEach((to, from, next) => {
    const userInfo = storeToRefs(useUser())?.userInfo
    if (!['/', '/login'].includes(to.path) && !userInfo.value.userId) {
        ElMessage.error('请登录！')
        next('/')
    } else {
        next()
    }
})
// 导出
export default router 